<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('原料信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <input type="hidden" id="warehouseId" name="warehouseId" th:value="${warehouse.id}">
        <input type="hidden" id="materialAmounts" name="materialAmounts" th:value="${materialAmounts}">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:material:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:material:remove')}]];
    var prefix = ctx + "system/material";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "原料信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '原料编号',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'description',
                    title: '描述'
                },
                {
                    field: 'cost',
                    title: '价格(元)'
                },
                {
                    field: 'supplier',
                    title: '供应商'
                },
                {
                    field: 'amount2',
                    title: '进货数量',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<input type="text" id="importAmount' + index + '"/>');
                        return actions.join('');
                    }
                }
                ]
        };
        $.table.init(options);
    });

    function submitHandler() {
        var materialIds = $.table.selectFirstColumns();

        if (materialIds.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var importAmounts = new Array();
        importAmounts.push(0);
        var len = document.getElementById("materialAmounts").value;
        for (var i = 0; i < len; i++)
            importAmounts.push(document.getElementById("importAmount" + i).value)
        var data = {"warehouseId": $("#warehouseId").val(), "materialIds": materialIds.join(), "importAmounts": importAmounts.join()};
        $.operate.save("/system/warehouse/warehouseInventory/importMaterial/importMaterialSubmit", data);
    }
</script>
</body>
</html>